package xworker.javafx.control;

import javafx.scene.control.ProgressIndicator;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;

public class ProgressIndicatorActions {
	static{
		PropertyFactory.regist(ProgressIndicator.class, "progressProperty", o -> {
			ProgressIndicator obj = (ProgressIndicator) o;
			return obj.progressProperty();
		});
	}

	public static void init(ProgressIndicator p, Thing thing, ActionContext actionContext) {
		ControlActions.init(p, thing, actionContext);

		if (thing.valueExists("progress")) {
			p.setProgress(thing.getDouble("progress"));
		}		
	}
	
	public static ProgressIndicator create(ActionContext actionContext) {
		Thing self = actionContext.getObject("self");
		
		ProgressIndicator item = new ProgressIndicator();
		init(item, self, actionContext);
		actionContext.g().put(self.getMetadata().getName(), item);
		
		actionContext.peek().put("parent", item);
		for(Thing child : self.getChilds()) {
			child.doAction("create", actionContext);			
		}
		
		return item;
	}
}
